/*
 * Copyright 2012 Benoît Combe <benoit.combe@gmail.com>.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package fr.ipst.spot.entites;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Benoît Combe <benoit.combe@gmail.com>
 */
@Entity
@Table(name = "Pdf", catalog = "SPOT", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Pdf.findAll", query = "SELECT p FROM Pdf p"),
    @NamedQuery(name = "Pdf.findByIdPdf", query = "SELECT p FROM Pdf p WHERE p.idPdf = :idPdf"),
    @NamedQuery(name = "Pdf.findByAuteur", query = "SELECT p FROM Pdf p WHERE p.auteur = :auteur"),
    @NamedQuery(name = "Pdf.findByDate", query = "SELECT p FROM Pdf p WHERE p.date = :date"),
    @NamedQuery(name = "Pdf.findByTitre", query = "SELECT p FROM Pdf p WHERE p.titre = :titre"),
    @NamedQuery(name = "Pdf.findByPath", query = "SELECT p FROM Pdf p WHERE p.path = :path"),
    @NamedQuery(name = "Pdf.findByResume", query = "SELECT p FROM Pdf p WHERE p.resume = :resume")})
public class Pdf extends Fichier implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @NotNull
    @Column(name = "idPdf", nullable = false)
    private Integer idPdf;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 45)
    @Column(name = "auteur", nullable = false, length = 45)
    private String auteur;
    @Basic(optional = false)
    @NotNull
    @Column(name = "date", nullable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date date;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 255)
    @Column(name = "titre", nullable = false, length = 255)
    private String titre;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 255)
    @Column(name = "path", nullable = false, length = 255)
    private String path;
    @Size(max = 10000)
    @Column(name = "resume", length = 10000)
    private String resume;
    @JoinTable(name = "PdfEvenement", joinColumns = {
        @JoinColumn(name = "idPdf", referencedColumnName = "idPdf", nullable = false)}, inverseJoinColumns = {
        @JoinColumn(name = "idEvenement", referencedColumnName = "idEvenement", nullable = false)})
    @ManyToMany(fetch = FetchType.LAZY)
    private List<Evenement> evenementList;

    /**
     *
     */
    public Pdf() {
        this.evenementList = new ArrayList<Evenement>();
    }

    /**
     *
     * @param idPdf
     */
    public Pdf(Integer idPdf) {
        this.idPdf = idPdf;
    }

    /**
     *
     * @param idPdf
     * @param auteur
     * @param date
     * @param titre
     * @param path
     */
    public Pdf(Integer idPdf, String auteur, Date date, String titre, String path) {
        this.idPdf = idPdf;
        this.auteur = auteur;
        this.date = date;
        this.titre = titre;
        this.path = path;
    }

    /**
     *
     * @return
     */
    public Integer getIdPdf() {
        return idPdf;
    }

    /**
     *
     * @param idPdf
     */
    public void setIdPdf(Integer idPdf) {
        this.idPdf = idPdf;
    }

    /**
     *
     * @return
     */
    public String getAuteur() {
        return auteur;
    }

    /**
     *
     * @param auteur
     */
    public void setAuteur(String auteur) {
        this.auteur = auteur;
    }

    /**
     *
     * @return
     */
    @Override
    public Date getDate() {
        return date;
    }

    /**
     *
     * @param date
     */
    @Override
    public void setDate(Date date) {
        this.date = date;
    }

    /**
     *
     * @return
     */
    @Override
    public String getTitre() {
        return titre;
    }

    /**
     *
     * @param titre
     */
    @Override
    public void setTitre(String titre) {
        this.titre = titre;
    }

    /**
     *
     * @return
     */
    @Override
    public String getPath() {
        return path;
    }

    /**
     *
     * @param path
     */
    @Override
    public void setPath(String path) {
        this.path = path;
    }

    /**
     *
     * @return
     */
    @Override
    public String getResume() {
        return resume;
    }

    /**
     *
     * @param resume
     */
    @Override
    public void setResume(String resume) {
        this.resume = resume;
    }

    /**
     *
     * @return
     */
    @XmlTransient
    @Override
    public List<Evenement> getEvenementList() {
        return evenementList;
    }

    /**
     *
     * @param evenementList
     */
    @Override
    public void setEvenementList(List<Evenement> evenementList) {
        this.evenementList = evenementList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idPdf != null ? idPdf.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Pdf)) {
            return false;
        }
        Pdf other = (Pdf) object;
        if ((this.idPdf == null && other.idPdf != null) || (this.idPdf != null && !this.idPdf.equals(other.idPdf))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "fr.ipst.spot.entites.Pdf[ idPdf=" + idPdf + " ]";
    }

    /**
     *
     * @return
     */
    @Override
    public Integer getId() {
        return this.idPdf;
    }
}
